package com.jmyd.coupon.server.domain.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jmyd.coupon.server.domain.po.SceneCouponUseRecord;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 优惠券使用信息列表
 *
 * @author samphin
 * @since 2021-7-13 18:08:52
 */
@Getter
@Setter
@NoArgsConstructor
public class SceneCouponListVo implements Serializable {


    private static final long serialVersionUID = 8938276290374748473L;

    private Long moduleId;

    private String moduleName;

    private Long userId;

    private String userName;

    private String useStatus;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date validStartTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date validEndTime;

    /**
     * 将poList->voList
     *
     * @author samphin
     * @date 2019-9-4 15:31:05
     */
    public static List<SceneCouponListVo> buildVoList(List<SceneCouponUseRecord> poList) {
        if (CollectionUtils.isEmpty(poList)) {
            return new ArrayList<>(1);
        }
        return poList.stream().map(po -> {
            SceneCouponListVo vo = new SceneCouponListVo();
            BeanUtils.copyProperties(po, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}
